package com.gxa.service.impl;

import com.gxa.common.JsonResult;
import com.gxa.common.PageRecv;
import com.gxa.common.R;
import com.gxa.mapper.CarMapper;
import com.gxa.mapper.DocumentaryMapper;
import com.gxa.pojo.Car;
import com.gxa.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 张剑宇
 * Date: 2021/12/02 18:38
 * Description:
 * Version: V1.0
 */
@Service
public class CarServiceImpl implements CarService {
    @Autowired(required = false)
    private CarMapper carMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public R addCar(Car car) {
        carMapper.addCarMapper(car);
        R r=new R();
        r.setMsg("添加成功");
        r.setCode(200);
        return r;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateCar(Car car) {
        carMapper.updateCarMapper(car);
        R r=new R();
        r.setMsg("修改成功");
        r.setCode(200);
        return r;
    }

    @Override
    public R deleteCar(Integer car_id) {
        carMapper.deleteCarMapper(car_id);
        R r=new R();
        r.setMsg("删除成功");
        r.setCode(200);
        return r;
    }

    @Override
    public JsonResult<Car> findCarList(PageRecv<Car> pageRecv) {

        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);
        //获取查询条件实体
        Car car=pageRecv.getData();
        //调用mapper方法，返回查询结果list
        List<Car> list=carMapper.findCarListMapper(pageRecv);
//        Integer count=documentaryMapper.searchDocumentaryListCountMapper(pageRecv);

        //将list和count条数塞入r,响应成功返回
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setCount(1);

        r.setMsg("查询成功");
        r.setData(list);

        return r;
    }
}
